/**
 * Created by WYH on 17/8/25.
 */
angular.module('tribalc').controller('WelfareController', ['$state',
    '$rootScope' ,'$scope', 'Api', 'RentProtocolModel',
    function ($state,$rootScope ,$scope, Api, CompanyModel) {
        $scope.gotoAddWelfare = gotoAddWelfare;
        $scope.getLocalTime = getLocalTime
        $scope.pageNum=0;
        $scope.getstatus = getstatus;
        // $scope.getCompaniesList=getCompaniesList;
        $scope.isCompanyInfo = false;

        $scope.companiesList = [];
        $scope.nextSkip = null;
        $scope.prevSkip = null;
        $scope.hasMore = false;
        $scope.gotoMoreWelfare = gotoMoreWelfare;
        $scope.walletInfo = {};

        getWelFareList();
        getWelfareWalletInfo();
        function getWelfareWalletInfo() {
            Api.getWelfareWalletInfo(null,function (result) {
                console.log(result);
                $scope.walletInfo = result.data;
            })
        }
        function getWelFareList() {
            // console.log("getWelFareList");
            Api.getWelfareList(null,null,null,function (result) {
                $scope.welfareData = result.data.content;
                // console.log(result.data.content);
            });
        }
        function getLocalTime(nS) {
            var date = new Date(nS);
            Y = date.getFullYear() + '年';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
            D = date.getDate() + '日';
            h = date.getHours() + ':';
            m = date.getMinutes()
            return Y + M + D ;
        }

        function getstatus(status) {
            return{'FINISHED':'正常','':''}[status]
        }

        function gotoAddWelfare() {
            $state.go('company.companyaddWelfare');
        }
        // getCompaniesList(null,null,'desc');
        // function getCompaniesList(limitSize,sortSkip,sort) {
        //     Api.getCompanies(limitSize,sortSkip,sort, function (result) {
        //         console.log(result);
        //         $scope.pageNum ++;
        //         $scope.nextSkip = result.data.nextSkip;
        //         $scope.hasMore = result.data.hasMore;
        //         if (result.data.prevSkip != null)
        //         {
        //             var numPage = result.data.prevSkip.substr(result.data.prevSkip.length-1,1);
        //             var number = parseInt(numPage) > 1 ? parseInt(numPage) - 1 : parseInt(numPage);
        //             $scope.prevSkip = result.data.prevSkip.substr(0,result.data.prevSkip.length-1) + number;
        //         }
        //
        //         setupCompaniesList(result.data.content);
        //         $scope.companiesList = [];
        //     });
        //
        // }
        // function setupCompaniesList(array) {
        //     array.forEach(function (value) {
        //         Api.getCompanyDetail(value.id,function (result) {
        //             $scope.companiesList.push(result.data);
        //         });
        //     });
        // }
        function gotoMoreWelfare(){
            $state.go('company.companymoreWelfare');
        }


    }]);